/*
 * Albareth - an action roleplaying game.
 * Copyright (C) 2008 Jens Anuth
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 *   02110-1301, USA.
 * 
 * $Id: IconGridMenuView.java 46 2008-05-15 18:09:39Z jens464 $
*/
package albareth.frontend.slick.ui;

import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;

import albareth.frontend.TileCollection;
import albareth.frontend.slick.SlickResources;
import frosch.util.Size;

public class IconGridMenuView implements MenuView
{
    public static final Color COLOR_DISABLED = new Color(40, 40, 40, 255);
    public static final Color COLOR_HOVER    = new Color(255, 245, 180, 255);

    protected float _iconScale = 2.0f;
    protected Size _cellsPerPage = new Size(4, 4);
    protected Size _cellSize = new Size(
            TileCollection.getDefaultTileWidth(),
            TileCollection.getDefaultTileHeight()
    );

    
    public IconGridMenuView(int cellWidth, int cellHeight,
                            int cellsHoriz, int cellsVert)
    {
        _cellSize = new Size(cellWidth, cellHeight);
        _cellsPerPage = new Size(cellsHoriz, cellsVert);
    }
    
    public int getItemPageOffsetAt(BasicMenuFrame menu, int x, int y)
    {
        int ix = x / _cellSize.width;
        int iy = y / _cellSize.height;
        return ix + _cellsPerPage.width * iy;
    }

    public int getItemXPosition(BasicMenuFrame menu, int itemPageOffset)
    {
        return (itemPageOffset % _cellsPerPage.width) * _cellSize.height;
    }

    public int getItemYPosition(BasicMenuFrame menu, int itemPageOffset)
    {
        return (itemPageOffset / _cellsPerPage.width) * _cellSize.height;
    }

    public int getItemsPerPage(BasicMenuFrame menu)
    {
        return _cellsPerPage.area();
    }

    public int getRowsPerPage(BasicMenuFrame menu)
    {
        return _cellsPerPage.height;
    }


    public void renderMenuItem(BasicMenuFrame menu, MenuItem item, Graphics g,
                               int screenX, int screenY, boolean highlighted)
    {
        Image iconImage = item.getIconImage();
        if (iconImage != null) {
            //Color filter = highlighted ? COLOR_HOVER : Color.white;
            iconImage.draw(screenX, screenY, _iconScale);
        }
        if (highlighted) {
            SlickResources.MENU_ITEM_SELECTED.draw(screenX, screenY, _iconScale);
        }
    }



}

